package com.jaof.airplane.ui;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import com.jaof.airplane.R;
import com.jaof.airplane.TimerAirplaneActivity;

public class SplashActivity extends Activity {

	private static final int MSG_SWITCH_ACTIVITY = 1;

	private static final int SHOW_DURATION = 1000;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.splash_activity);

		mHandler.sendEmptyMessageDelayed(MSG_SWITCH_ACTIVITY, SHOW_DURATION);
	}

	private Bitmap splashBitmap = null;

	private Handler mHandler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case MSG_SWITCH_ACTIVITY:

				loadMainActvity();
				finish();
				break;
			}
		}
	};

	private void loadMainActvity() {
		if (splashBitmap != null && !splashBitmap.isRecycled()) {
			splashBitmap.recycle();
		}
		Intent intent = new Intent(this, TimerAirplaneActivity.class);
		startActivity(intent);
	}

	@Override
	protected void onDestroy() {
		if (mHandler != null) {
			mHandler.removeCallbacksAndMessages(null);
		}
		super.onDestroy();
	}

}
